<template>
	<el-card class="form-container">
		<el-form :model="dataForm" ref="dataForm" :rules="dataRule" @keyup.enter.native="dataFormSubmitHandle()" label-width="120px">
			<el-form-item label="等级名称" prop="levelName">
				<el-input v-model="dataForm.levelName" placeholder="请输入等级名称"></el-input>
			</el-form-item>
			<el-form-item label="等级成长值" prop="growthPoint">
				<el-input v-model="dataForm.growthPoint" placeholder="请输入等级需要的成长值"></el-input>
			</el-form-item>
			<el-form-item label="默认等级" prop="isDefaultLevel">
				<el-radio-group v-model="dataForm.isDefaultLevel">
					<el-radio label="1">是</el-radio>
					<el-radio label="2">否</el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item label="免运费标准" prop="freeFreightPoint">
				<el-input v-model="dataForm.freeFreightPoint" placeholder="请输入免运费标准"></el-input>
			</el-form-item>
			<el-form-item label="评价获取成长值" prop="commentGrowthPoint">
				<el-input v-model="dataForm.commentGrowthPoint" placeholder="请输入每次评价获取的成长值"></el-input>
			</el-form-item>
			<el-form-item label="免邮特权" prop="priviledgeFreeFreight">
				<el-radio-group v-model="dataForm.priviledgeFreeFreight">
					<el-radio label="1">是</el-radio>
					<el-radio label="2">否</el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item label="会员价格特权" prop="priviledgeMemberPrice">
				<el-radio-group v-model="dataForm.priviledgeMemberPrice">
					<el-radio label="1">是</el-radio>
					<el-radio label="2">否</el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item label="生日特权" prop="priviledgeBirthday">
				<el-radio-group v-model="dataForm.priviledgeBirthday">
					<el-radio label="1">是</el-radio>
					<el-radio label="2">否</el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item label="备注" prop="note">
				<el-input v-model="dataForm.note" placeholder="请输入备注"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button @click="cancel">取消</el-button>
				<el-button type="primary" @click="submit('dataForm')">确定</el-button>
			</el-form-item>
		</el-form>
	</el-card>
</template>

<script>
	import { addUserLevel } from '@/api/crm/userLevel'
	export default {
		name: 'add-userLevel',
		data() {
			return {
				dataForm: {
					levelName: '',
					growthPoint: '',
					isDefaultLevel: '',
					freeFreightPoint: '',
					commentGrowthPoint: '',
					priviledgeFreeFreight: '',
					priviledgeMemberPrice: '',
					priviledgeBirthday: '',
					note: '',
					createTime: '',
					updateTime: '',
				},
				dataRule: {
					levelName: [{
							required: true,
							message: '请输入等级名称',
							trigger: 'blur'
						},
					],
					growthPoint: [{
							required: true,
							message: '请输入等级需要的成长值',
							trigger: 'blur'
						},
					],
					isDefaultLevel: [{
							required: true,
							message: '请输入是否为默认等级 1是 2否',
							trigger: 'blur'
						},
					],
					freeFreightPoint: [{
							required: true,
							message: '请输入免运费标准',
							trigger: 'blur'
						},
					],
					commentGrowthPoint: [{
							required: true,
							message: '请输入每次评价获取的成长值',
							trigger: 'blur'
						},
					],
					priviledgeFreeFreight: [{
							required: true,
							message: '请输入是否有免邮特权 1是 2否',
							trigger: 'blur'
						},
					],
					priviledgeMemberPrice: [{
							required: true,
							message: '请输入是否有会员价格特权 1是2否',
							trigger: 'blur'
						},
					],
					priviledgeBirthday: [{
							required: true,
							message: '请输入是否有生日特权 1是 2否',
							trigger: 'blur'
						},
					],
					note: [{
							required: true,
							message: '请输入备注',
							trigger: 'blur'
						},
					],
				}
			}
		},
		methods: {
			cancel() {
				this.$router.go(-1)
			},
			submit() {
				const set = this.$refs;
				set['dataForm'].validate((valid) => {
					if (!valid) {
						return false
					}
					addUserLevel(this.dataForm).then(() => {
						this.$notify({
							title: '添加成功',
							message: '添加成功',
							type: 'success',
							duration: 2000,
							onClose: this.$router.go(-1)
						})
					})
				})
			}
		}
	}
</script>

<style>
</style>
